package com.liuqi.aiagent.transfer;

import com.liuqi.aiagent.transfer.model.Result;
import com.liuqi.aiagent.transfer.model.ResultList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * Response Result Build
 *
 * @author liuqi
 * @date 2025/7/3 16:07
 **/
public abstract class ApiResult {

    public static Map<String, Object> buildData(String key, Object value) {
        Map<String, Object> data = new HashMap<>(1);
        data.put(key, value);
        return data;
    }

    public static <T> Result<T> createResult(int code, String msg, T data) {
        return new Result(code, msg, data);
    }

    public static <T> ResultList<T> createResultList(int code, String msg, Object data, List<T> list, long total) {
        return new ResultList<T>(code, msg, data, total, list);
    }

    public static Result success() {
        return success(null, null);
    }

    public static Result success(String msg) {
        return success(msg, null);
    }

    public static <T> Result<T> success(T data) {
        return success(null, data);
    }

    public static <T> Result<T> success(String msg, T data) {
        return createResult(Status.SUCCESS.code(), msg == null ? Status.SUCCESS.msg() : msg, data);
    }

    public static <T> ResultList<T> success(List<T> list, long total) {
        return success(list, total, null, null);
    }

    public static <T> ResultList<T> success(List<T> list, long total, String msg) {
        return success(list, total, msg, null);
    }

    public static <T> ResultList<T> success(List<T> list, long total, Object data) {
        return success(list, total, null, data);
    }

    public static <T> ResultList<T> success(List<T> list, long total, String msg, Object data) {
        return createResultList(Status.SUCCESS.code(), msg == null ? Status.SUCCESS.msg() : msg, data, list, total);
    }

    public static Result fail(String msg) {
        return fail(msg, null);
    }

    public static Result fail(String msg, Object data) {
        return createResult(Status.FAIL.code(), msg == null ? Status.FAIL.msg() : msg, data);
    }

    public static <T> ResultList<T> failList(String msg) {
        return failList(msg, null);
    }

    public static <T> ResultList<T> failList(Object data) {
        return failList(null, data);
    }

    public static <T> ResultList<T> failList(String msg, Object data) {
        return createResultList(Status.FAIL.code(), msg == null ? Status.FAIL.msg() : msg, data, null, 0);
    }

}
